<?php

namespace App\Http\Controllers;

use App\Exceptions\BusinessException;
use App\Services\WriteOffService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class WriteOffController extends Controller
{
    /**
     * 核销
     * @param Request $request
     * @return JsonResponse
     * @throws BusinessException
     */
    public function writeOff(Request $request)
    {
        $uid = $request->uid;
        $orderId = $request->post('order_id');
        $sellType = $request->post('sell_type');
        $sellId = $request->post('sell_id');
        WriteOffService::getInstance()->writeOff($uid, $orderId, $sellType, $sellId);

        return $this->success();
    }

    /**
     * 核销记录
     * @param Request $request
     * @return JsonResponse
     */
    public function writeOffRecord(Request $request)
    {
        $uid = $request->uid;
        $page = $request->input('page', 1);
        $pageSize = $request->input('psize', 10);
        $data = WriteOffService::getInstance()->writeOffRecord($uid, $page, $pageSize);

        return $this->success($data);
    }
}
